package com.joycessh.action;

import java.sql.SQLException;
import java.util.Map;

import com.joycessh.dao.UserDao;
import com.joycessh.dao.impl.UserDaoImpl;
import com.joycessh.vo.LoginVO;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	/**
	 * @author joycessh
	 */
	private static final long serialVersionUID = 1L;
	
	private LoginVO user;
	private UserDao uDao;
	//private Map<String, Object> session = null;
	public LoginVO getUser() {
		return user;
	}
	public void setUser(LoginVO user) {
		this.user = user;
	}
	
	/*public void setSession(Map<String, Object> session) {
		this.session = session;
	}*/
	
	public String execute() {
		// TODO Auto-generated method stub
		try {
			uDao = new UserDaoImpl();
			if (uDao.checkUser(user)) {
				ActionContext actionContext = ActionContext.getContext();
			    @SuppressWarnings("unchecked")
				Map<String, String> session = actionContext.getSession();
				session.put("username", user.getUsername());
				return "success";
			} else {
				return "fail";
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return "input";
		}
		
	}
				
}
